Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Fixes #322 (among other things).
Improve and simplify the API used for
CollisionLayers
andSpatialQueryFilter
.Solution
Add a
LayerMask
struct that stores a bitmask used for collision layers. Thegroups
andmasks
properties have also been renamed tomemberships
andfilters
, because "groups" and "layers" sound like the same thing, and "masks" might be confusing since it's a single bitmask (just like groups/memberships). The new naming is also what Rapier uses.A
LayerMask
can be created from au32
, a type implementingPhysicsLayer
, or an array of layers.CollisionLayers::new
now takesimpl Into<LayerMask>
. All of the following work:LayerMask
also allows us to reduce the number ofCollisionLayers
methods.contains_group
/contains_mask
,add_group
/add_mask
and so on have been removed in favor of simply calling methods likeadd
orremove
on the actual properties.The methods mutate in place instead of returning a copy, which fixes #322.
SpatialQueryFilter
also now usesLayerMask
for its masks, and its constructors have been improved.new
has been removed for redundancy,with_mask_from_bits
has been removed, and instead it has the methodsfrom_mask
,from_excluded_entities
,with_mask
, andwith_excluded_entities
.Changelog
Added
LayerMask
structSpatialQueryFilter::from_mask
SpatialQueryFilter::from_excluded_entities
Changed
CollisionLayers
groups
andmasks
ofCollisionLayers
are now calledmemberships
andfilters
CollisionLayers
storesLayerMask
s for memberships and filtersimpl IntoIterator<Item = impl PhysicsLayer>
now takeimpl Into<LayerMask>
CollisionLayers::all()
to constantCollisionLayers::ALL
CollisionLayers::none()
to constantCollisionLayers::NONE
CollisionLayers::all_groups()
to constantCollisionLayers::ALL_MEMBERSHIPS
CollisionLayers::all_masks()
to constantCollisionLayers::ALL_FILTERS
SpatialQueryFilter
SpatialQueryFilter
stores aLayerMask
for collision masksSpatialQueryFilter::with_mask
now takesimpl Into<LayerMask>
SpatialQueryFilter::without_entities
towith_excluded_entities
for consistencyRemoved
CollisionLayers::add_group
andCollisionLayers::add_mask
CollisionLayers::remove_group
andCollisionLayers::remove_mask
CollisionLayers::contains_group
andCollisionLayers::contains_mask
CollisionLayers::groups_bits
andCollisionLayers::masks_bits
(you could get e.g.layers.groups.0
instead)SpatialQueryFilter::new
SpatialQueryFilter::with_masks_from_bits
Migration Guide
layers.add_group(...)
withlayers.memberships.add(...)
and so on, and similarly for masks/filtersCollisionLayers::all()
toCollisionLayers::ALL
CollisionLayers::none()
toCollisionLayers::NONE
CollisionLayers::all_groups()
toCollisionLayers::ALL_MEMBERSHIPS
CollisionLayers::all_masks()
toCollisionLayers::ALL_FILTERS
SpatialQueryFilter::new()
toSpatialQueryFilter::default()
or use theSpatialQueryFilter::from_mask
orSpatialQueryFilter::from_excluded_entities
constructorsSpatialQueryFilter::without_entities
towith_excluded_entities
CollisionLayers::groups_bits()
andCollisionLayers::masks_bits()
tolayers.memberships.0
andlayers.filters.0